﻿using Siasun.AFC.AfcCommonLib.Base;
using Siasun.AFC.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Siasun.AFC.RtPlatfromGui.Dao.Define
{
    public class RtMenuDataModel
    {
        public string Id { get; set; }
        public string ParentMenuId { get; set; }
        public string MenuName { get; set; }
        public string DllName { get; set; }
        public string DllFilePath { get; set; }
        public string NamespacePath { get; set; }
        public string MenuPageName { get; set; }
        public int MenuIsable { get; set; }
        public int MenuIsShow { get; set; }
        public int MenuIsShowDialog { get; set; }
        public DateTime MenuMedifyTime { get; set; }
        public string NodeType { get; set; }

        /// <summary>
        /// 数据实例与对象实体类集合的转换
        /// </summary>
        /// <param name="rData"></param>
        /// <returns></returns>
        public static RtMenuDataModel ConvertData(Dictionary<string, string> rData)
        {
            RtMenuDataModel model = new RtMenuDataModel();
            try
            {
                model.Id = rData["ID"];
                model.ParentMenuId = rData["PARENT_MENU_ID"];
                model.MenuName = rData["MENU_NAME"];
                model.DllName = rData["DLL_NAME"];
                model.DllFilePath = rData["DLL_FILE_PATH"];
                model.NamespacePath = rData["NAMESPACE_PATH"];
                model.MenuPageName = rData["MENU_PAGE_NAME"];
                model.MenuIsable = CommApi.GetIntDataFromString(rData["MENU_ISABLE"]);
                model.MenuIsShow = CommApi.GetIntDataFromString(rData["MENU_ISSHOW"]);
                model.MenuIsShowDialog = CommApi.GetIntDataFromString(rData["MENU_ISSHOWDIALOG"]);
                model.MenuMedifyTime = CommApi.GetDateTimeFromString(rData["MENU_MEDIFY_TIME"]);
                model.NodeType = rData["NODE_TYPE"];
            }
            catch
            {
                LoggerInf.Error("获取箱体操作数据表时，所查询字段不存在，检查表结构是否改变！");
                return null;
            }
            return model;
        }

        /// <summary>
        /// 数据实例与对象实体类集合的转换
        /// </summary>
        /// <param name="rData"></param>
        /// <returns></returns>
        public static List<RtMenuDataModel> ConvertDataArray(List<Dictionary<string, string>> rData)
        {
            List<RtMenuDataModel> modelList = new List<RtMenuDataModel>();
            RtMenuDataModel model = null;

            foreach (Dictionary<string, string> dataStr in rData)
            {
                try
                {
                    model = new RtMenuDataModel();
                    model.Id = dataStr["ID"];
                    model.ParentMenuId = dataStr["PARENT_MENU_ID"];
                    model.MenuName = dataStr["MENU_NAME"];
                    model.DllName = dataStr["DLL_NAME"];
                    model.DllFilePath = dataStr["DLL_FILE_PATH"];
                    model.NamespacePath = dataStr["NAMESPACE_PATH"];
                    model.MenuPageName = dataStr["MENU_PAGE_NAME"];
                    model.MenuIsable = CommApi.GetIntDataFromString(dataStr["MENU_ISABLE"]);
                    model.MenuIsShow = CommApi.GetIntDataFromString(dataStr["MENU_ISSHOW"]);
                    model.MenuIsShowDialog = CommApi.GetIntDataFromString(dataStr["MENU_ISSHOWDIALOG"]);
                    model.MenuMedifyTime = CommApi.GetDateTimeFromString(dataStr["MENU_MEDIFY_TIME"]);
                    model.NodeType = dataStr["NODE_TYPE"];

                    modelList.Add(model);
                }
                catch
                {
                    LoggerInf.Error("获取箱体操作数据表时，所查询字段不存在，检查表结构是否改变！");
                }
            }
            return modelList;
        }
    }
}
